﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tour.szhome.common;
using TOUR.SZHOME.Attributes;
using TOUR.SZHOME.BLL;
using TOUR.SZHOME.Entity;

namespace tour.szhome.manage.area.Controllers
{
    [SelfOnly]
    public class ProjectController : Controller
    {
        //
        // GET: /Project/
        ProjectsBLL _projectbll = new ProjectsBLL();

        /// <summary>
        /// 项目列表页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 查看项目详情
        /// </summary>
        /// <returns></returns>
        public ActionResult Detail(int id = 0) 
        {
            ProjectsEntity model = new ProjectsEntity();
            model = _projectbll.GetProjectByID(id);
            return View(model);
        }

        /// <summary>
        /// 新增 or 编辑项目 视图
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit(int id = 0)
        {
            ProjectsEntity model = new ProjectsEntity();
            if (id != 0)
            {
                model = _projectbll.GetProjectByID(id);
            }
            ViewBag.ID = id;
            ViewBag.uploadAddress = System.Configuration.ConfigurationManager.AppSettings["UploadAddress"];//获取上传文件地址 
            ViewBag.Folder = "others/";   //获取当前子文件夹
            return View(model);
        }

        /// <summary>
        /// 获取项目列表
        /// </summary>
        /// <param name="name"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [ActionName("get_project_list")]
        public ActionResult GetProjectList(string name = "", int page = 1, int size = 10) 
        {
            PageSet pageSet = new PageSet()
            {
                PageIndex = page,
                PageSize = size,
            };
            var data = new
            {
                page = page,
                pageSize = size,
                list = _projectbll.GetProjectList(name, pageSet),
                recordCount = pageSet.RecordCount,
                totalpage = pageSet.PageCount
            };
            return Json(data);
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <returns></returns>
         [ValidateInput(false)]
        [ActionName("json_edit")]
        public ActionResult Json_Edit(ProjectsEntity model)
        {
            return Json(_projectbll.EditProject(model));
        }

        /// <summary>
        /// 根据ID删除对象
        /// </summary>
        /// <param name="nid"></param>
        /// <returns></returns>
        [ActionName("json_delete")]
        public ActionResult DelByID(int pid)
        {
            return Json(_projectbll.DelByID(pid), JsonRequestBehavior.AllowGet);
        }
    }
}
